package com.hyh.admin.controller.resources;

import com.hyh.ad.common.core.controller.BaseController;
import com.hyh.ad.common.core.domain.AjaxResult;
import com.hyh.ad.common.utils.SecurityUtils;
import com.hyh.admin.domain.resources.ResourcesRating;
import com.hyh.admin.domain.resources.ResourcesViews;
import com.hyh.admin.service.IResourcesRatingService;
import com.hyh.admin.service.IResourcesViewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/resources/rating")
@Api(tags = "资源评分管理")
public class ResourcesRatingController extends BaseController {
    @Autowired
    private IResourcesRatingService resourcesRatingService;


    /*
     * 添加资源评分
     */
    @PostMapping("/insert")
    @ApiOperation(value = "添加资源评分")
    public AjaxResult insert(@RequestBody ResourcesRating resourcesRating) {
        resourcesRating.setUserId(SecurityUtils.getLoginUser().getUser().getId());
        return toAjax(resourcesRatingService.insertResourcesRating(resourcesRating));
    }

    /*
     *统计资源评分
     */
    @GetMapping("/avg")
    @ApiOperation(value = "统计资源评分")
    public AjaxResult avg(@RequestParam Long resourcesId) {
        return AjaxResult.success(resourcesRatingService.selectResourcesRatingAvg(resourcesId));
    }


    /*
     * 查询我的资源评分
     */
    @GetMapping("/myScore/{resourcesId}")
    @ApiOperation(value = "查询我的资源评分")
    public AjaxResult MyScore(@PathVariable Long resourcesId) {
        return AjaxResult.success(resourcesRatingService.selectMyResourcesRating(resourcesId,SecurityUtils.getLoginUser().getUser().getId()));
    }

}
